#include "../globals/globals.h"
#include "screen.h"

void auto_start_btn_func() {
  // virtual btn start auto according to auto setting
  if (vb_auto->pressing()) {
    timer t;
    vb_auto->darker(false, 0.5);
    while (vb_auto->pressing()) {
      if (t.time() > 1000) {
        vb_auto->brighter();
        bool cancelled = false;
        while (Brain.Screen.pressing()) {
          if (!vb_auto->pressing()) {
            vb_auto->darker();
            cancelled = true;
          }
          wait(5);
        }
        if (!cancelled) {
          run_auto_background();
          screen_clear();
          buttons_show_up();
        }
      }
      wait(5);
    }
    vb_auto->darker(false);
  }
}
//////////////////////////
void imu_recalibrate_func() {
  // imu calibrate
  if (vb_gyro_rec->pressing()) {
    timer t;
    vb_gyro_rec->darker(false, 0.5);
    while (vb_gyro_rec->pressing()) {
      if (t.time() > 1000) {
        vb_gyro_rec->brighter();
        bool cancelled = false;
        while (Brain.Screen.pressing()) {
          if (!vb_gyro_rec->pressing()) {
            vb_gyro_rec->darker();
            cancelled = true;
          }
          wait(5);
        }
        if (!cancelled) {
          imu.calibrate();
          while_wait(imu.isCalibrating());
        }
        vb_gyro_rec->darker();
      }
      wait(5);
    }
    vb_gyro_rec->darker(false);
  }
}